package com.itcast.annotation;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * 框架类
 */
@Pro(className = "com.itcast.annotation.Demo2", methodName = "show2")
public class ReflectTest {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        // 1.解析注解
        // 1.1获取该类的字节码对象
        Class<ReflectTest> reflectTestClass = ReflectTest.class;
        // 2.获取注解对象
        // 其实就是在内存中生成了一个该注解接口的子类的实现对象
        Pro annotation = reflectTestClass.getAnnotation(Pro.class);
        // 3.调用注解对象中定义的抽象方法，获取返回值
        String className = annotation.className();
        String methodName = annotation.methodName();

        // 4.加载该类加载进内存
        Class<?> aClass = Class.forName(className);
        // 创建对象
        Object o = aClass.newInstance();
        // 获取方法对象
        Method method = aClass.getMethod(methodName);
        // 执行方法
        method.invoke(o);
    }
}
